package org.mat.admin.sys.controller;











import org.mat.admin.sys.api.domain.SysLogininfor;
import org.mat.admin.sys.controller.page.TableDataInfo;
import org.mat.admin.sys.service.ISysLogininforService;
import org.mat.admin.sys.util.CacheConstants;
import org.mat.framework.lang.dto.MatApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统访问记录
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/logininfor")
public class SysLogininforController extends BaseController
{
    @Autowired
    private ISysLogininforService logininforService;

    @Autowired
    private RedisService redisService;


    @GetMapping("/list")
    public TableDataInfo list(SysLogininfor logininfor)
    {
        startPage();
        List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
        return getDataTable(list);
    }


//    @PostMapping("/export")
//    public void export(HttpServletResponse response, SysLogininfor logininfor)
//    {
//        List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
//        ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(SysLogininfor.class);
//        util.exportExcel(response, list, "登录日志");
//    }


    @DeleteMapping("/{infoIds}")
    public MatApiResponse remove(@PathVariable Long[] infoIds)
    {
        return toAjax(logininforService.deleteLogininforByIds(infoIds));
    }


    @DeleteMapping("/clean")
    public MatApiResponse clean()
    {
        logininforService.cleanLogininfor();
        return MatApiResponse.success(null);
    }


    @GetMapping("/unlock/{userName}")
    public MatApiResponse unlock(@PathVariable("userName") String userName)
    {
        redisService.deleteObject(CacheConstants.PWD_ERR_CNT_KEY + userName);
        return success();
    }

    @PostMapping
    public MatApiResponse add(@RequestBody SysLogininfor logininfor)
    {
        return toAjax(logininforService.insertLogininfor(logininfor));
    }
}
